package com.liukai.bishe.utils;

import com.github.mikephil.charting.data.PieEntry;
import com.liukai.bishe.model.doman.transaction.Transaction;
import com.liukai.bishe.model.doman.transaction.TransactionTotal;
import com.liukai.bishe.model.doman.transaction.TransactionUseTime;
import com.liukai.bishe.model.doman.user.User;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Constants {

    public static final String BASEURL = "http://www.liukai.space:12345";
//    public static final String BASEURL = "http://192.168.43.121:12345";
//    public static final String BASEURL = "http://192.168.1.15:12345";

    public static final int REQUEST_CAMERA = 100;
    public static final int REQUEST_GALLERY = 101;
    public static final int REQUEST_CROP = 102;
    public static final int REQUEST_ChANGE_USERINFO = 103;
    public static final int REQUEST_ChANGE_USERINFO_SUCCESS = 104;

    public static final int REQUEST_ChANGE_NICKNAME_SUCCESS = 105;
    public static final int REQUEST_ChANGE_SEX_SUCCESS = 106;
    public static final int REQUEST_ChANGE_BIRTHDAY_SUCCESS = 107;
    public static final int REQUEST_ChANGE_DESCRIBE_SUCCESS = 108;
    public static final int REQUEST_ChANGE_PASSWORD_SUCCESS = 109;

    private static Map<String,String> userInfoMap = new HashMap<>();

    public static Map<String, String> getUserInfoMap() {
        return userInfoMap;
    }

    public static void setUserInfoMap(User user) {
        userInfoMap.put("昵称",user.getNickname());
        userInfoMap.put("性别",user.getSex());
        userInfoMap.put("出生年月",user.getBirthday());
        userInfoMap.put("个性签名",user.getUserdescribe());
        userInfoMap.put("密码",user.getPassword());
        userInfoList.add("昵称");
        userInfoList.add("性别");
        userInfoList.add("出生年月");
        userInfoList.add("个性签名");
        userInfoList.add("密码");
    }

    private static List<String> userInfoList = new ArrayList<>();

    public static List<String> getUserInfoList() {
        return userInfoList;
    }

    public static void setUserInfoList() {
        Constants.userInfoList.clear();
    }

    public static final String ENDPOINT = "http://oss-cn-chengdu.aliyuncs.com";//与个人的存储区域有关
    public static final String BUCKET_NAME = "bi-she";//上传仓库名
    public static final String ACCESSKEYID = "LTAI4FuR3GTZqeTU2ramcy7v";// ID
    public static final String ACCESSKEYSERCRET = "Q8errqaN8rkZpam7qzJWMlIj5x9ssT"; // 密码


    private static User userInfo = new User();

    public static User getUserInfo() {
        return userInfo;
    }

    public static void setUser(User user){
        Constants.userInfo = user;
//        Constants.setUserInfoMap(user);
    }



    public static String getNowTime(long timeStamp){

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(timeStamp);
        return simpleDateFormat.format(date);

    }

    private static List<Transaction> sTransactionList = new ArrayList<>();
    private static List<TransactionUseTime> sTransactionUseTimeList = new ArrayList<>();
    private static List<TransactionTotal> sTransactionTotalList = new ArrayList<>();

    private static List<PieEntry> sPieEntryList = new ArrayList<>();

    public static List<PieEntry> getPieEntryList() {
        return sPieEntryList;
    }

    public static void setPieEntryList(List<TransactionTotal> transactionTotals) {
        if (sPieEntryList != null) {
            sPieEntryList.clear();
        }
        for (int i = 0;i < transactionTotals.size();i ++){
            TransactionTotal transactionTotal = transactionTotals.get(i);
            String timeString = transactionTotal.getTotaltime();
            String time1 = (DateUtils.longTimeToMinuties(Long.valueOf(timeString)));
            int time = Integer.valueOf(time1);
            sPieEntryList.add(new PieEntry(time,transactionTotal.getTransactionname()));

        }

    }

    public static List<TransactionTotal> getTransactionTotalList() {
        return sTransactionTotalList;
    }

    public static void setTransactionTotalList(List<TransactionTotal> transactionTotalList) {
        if (sTransactionTotalList != null){
            sTransactionTotalList.clear();
        }
        sTransactionTotalList.addAll(transactionTotalList);
        setPieEntryList(transactionTotalList);
    }

    public static List<Transaction> getTransactionList() {
        return sTransactionList;
    }

    public static void setTransactionList(List<Transaction> transactionList) {
        if (sTransactionList != null) {
            sTransactionList.clear();
        }
        sTransactionList.addAll(transactionList);
    }

    public static List<TransactionUseTime> getTransactionUseTimeList() {
        return sTransactionUseTimeList;
    }

    public static void setTransactionUseTimeList(List<TransactionUseTime> transactionUseTimeList) {
        if (sTransactionUseTimeList != null){
            sTransactionUseTimeList.clear();
        }
        sTransactionUseTimeList.addAll(transactionUseTimeList);
    }



}
